package org.opens.config;

import lombok.extern.slf4j.Slf4j;
import org.opens.controller.DbController;
import org.opens.controller.FileController;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("org.opens")
@Slf4j
@ConditionalOnProperty(prefix = "netty", name = "enable", havingValue = "true", matchIfMissing = false)
public class NettyAutoConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "netty", name = "type", havingValue = "file")
    public FileController fileController() {
        log.info("netty配置文件方式已初始化");
        // 自动配置代码
        return new FileController();
    }

    @Bean
    @ConditionalOnProperty(prefix = "netty", name = "type", havingValue = "db")
    public DbController dbController() {
        log.info("netty数据库方式已初始化");
        // 自动配置代码
        return new DbController();
    }

}
